package ui.arena;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.bindings.NotNullObservable;
import org.uqbar.arena.layout.VerticalLayout;
//import org.uqbar.arena.bindings.NotNullObservable;
//import org.uqbar.arena.layout.ColumnLayout;
//import org.uqbar.arena.layout.HorizontalLayout;
import org.uqbar.arena.widgets.Button;
//import org.uqbar.arena.widgets.Label;
//import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.tables.Column;
import org.uqbar.arena.widgets.tables.Table;
//import org.uqbar.arena.widgets.TextBox;
//import org.uqbar.arena.widgets.tables.Column;
//import org.uqbar.arena.widgets.tables.Table;
//import org.uqbar.arena.windows.Dialog;
import org.uqbar.arena.windows.SimpleWindow;
import org.uqbar.arena.windows.Window;
import org.uqbar.arena.windows.WindowOwner;

import com.uqbar.commons.collections.Transformer;

import asientos.Vuelo;

import usuarios.Usuario;

/**

 */
@SuppressWarnings("serial")
public abstract class VisorDeRegistrosWindow extends Window<Usuario> {

	public VisorDeRegistrosWindow(WindowOwner parent, Usuario model) {
		super(parent, model);
	}
	
	@Override
	public void createContents(Panel mainPanel) {
		this.setTitle(TituloVentanas.getInstance().getTituloVentana());
		
		this.setLabel(mainPanel);
		
		this.createFormPanel(mainPanel);
		
		Panel actionPanel = new Panel(mainPanel);
		
		new Button(actionPanel)
		.setCaption("Cerrar")
		.onClick(new MessageSend(this, "close"));	
		
	}



	
	protected void createFormPanel(Panel mainPanel) {		
		mainPanel.setLayout(new VerticalLayout());
		this.createResultsGrid(mainPanel);	
	}
	
	protected void createResultsGrid(Panel mainPanel) {
		
		Table<Vuelo> table = new Table<Vuelo>(mainPanel, Vuelo.class);
		table.setHeigth(200);
		table.setWidth(450);

		bindearTablaARegistro(table);
		

		this.describeResultsGrid(table);
	}


	protected void describeResultsGrid(Table<Vuelo> table) {
		
		new Column<Vuelo>(table) 
			.setTitle("Salida")
			.setFixedSize(150)
			.bindContentsToTransformer(new FechaDeSalidaVueloToStringTransformer());


		new Column<Vuelo>(table) 
		.setTitle("Aerolinea")
		.setFixedSize(150)
		.bindContentsToProperty("aerolinea");

		new Column<Vuelo>(table) 
		.setTitle("Vuelo")
		.setFixedSize(150)
		.bindContentsToProperty("codigoDeVuelo");

		new Column<Vuelo>(table) 
		.setTitle("Asiento")
		.setFixedSize(150)
		.bindContentsToProperty("numeroDeAsiento");
		
		new Column<Vuelo>(table) 
		.setTitle("Precio")
		.setFixedSize(150)
		.bindContentsToProperty("precio");
	}
	
	protected abstract void setLabel(Panel panel);
	
	
	protected abstract void bindearTablaARegistro(Table<Vuelo> table);
	
}